home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / File / Change Text Owner next >
Encoding:
Text File  |  1999-03-04  |  2.4 KB  |  95 lines  |  [TEXT/ToyS]

  1. property kasMaxDepth : 16 -- Maximum folders to follow down
  2.  
  3. property kasOwnerID : "R*ch" -- Owner to use
  4. property kasTypes : {"TEXT"} -- Files to adjust
  5.  
  6. property sasInfoLoc : {-1, -1}
  7.  
  8. global gasInfo
  9.  
  10.  
  11. on run
  12.     open {choose folder with prompt "Choose a folder with text files to convert…"}
  13. end run
  14.  
  15.  
  16. on open fsObjs
  17.     set gasInfo to display info titled ¬
  18.         "Changing Owner" message ¬
  19.         "Scanning…" located at sasInfoLoc
  20.     
  21.     set ftype to ""
  22.     if (option key down of (input state)) then ¬
  23.         set ftype to GetType()
  24.     
  25.     repeat with fsObj in fsObjs
  26.         SetFSOwner(fsObj, kasOwnerID, ftype, kasMaxDepth)
  27.     end repeat
  28.     
  29.     -- Close info window
  30.     set newLoc to screen location of (display info gasInfo with disposal)
  31.     
  32.     -- Save window location
  33.     if (newLoc is not sasInfoLoc) then set sasInfoLoc to newLoc
  34. end open
  35.  
  36.  
  37. on SetFSOwner(fsObj, ownerID, ftype, depth)
  38.     set info to basic info for fsObj
  39.     
  40.     if (the catalog kind of info is a folder) then
  41.         set daddy to (fsObj as string)
  42.         
  43.         -- Do text files
  44.         if (ftype is "") then
  45.             set itemList to the entries in fsObj whose types are in kasTypes
  46.         else
  47.             set itemList to the entries in fsObj
  48.         end if
  49.         
  50.         repeat with fname in itemList
  51.             SetFSOwner((daddy & fname) as alias, ownerID, ftype, depth)
  52.         end repeat
  53.         
  54.         -- Do further folders        
  55.         set depth to depth - 1
  56.         if (depth > 0) then
  57.             set itemList to the entries in fsObj whose types are in {"fold"}
  58.             
  59.             repeat with fname in itemList
  60.                 SetFSOwner((daddy & fname) as alias, ownerID, ftype, depth)
  61.             end repeat
  62.         end if
  63.     else if ((system type of info) is in kasTypes) or (ftype is not "") then
  64.         SetFileOwner(fsObj, ownerID, ftype)
  65.     else if ((system type of info) is "APPL") then
  66.         set the icon of (path to me) to (the icon for fsObj)
  67.         set kasOwnerID to (system creator of info)
  68.         collate (path to me) renaming it to ("Owned by " & (catalog name of info))
  69.     end if
  70.     
  71. end SetFSOwner
  72.  
  73.  
  74. on SetFileOwner(fsObj, newOwner, newType)
  75.     set x to fsObj as string
  76.     if ((length of x) > 255) then set x to "…" & (the text from character -254 to -1 of x)
  77.     display info gasInfo message x
  78.     set info to basic info for fsObj
  79.     set system creator of info to newOwner
  80.     if (newType is not "") then set system type of info to newType
  81.     set the catalog info of fsObj to info
  82. end SetFileOwner
  83.  
  84.  
  85. on GetType()
  86.     display dialog ("Change the type of the dropped files to:") ¬
  87.         default answer "TEXT" default button 2
  88.     set ftype to text returned of the result
  89.     if length of ftype is not 4 then
  90.         beep
  91.         set ftype to ""
  92.     end if
  93.     return ftype
  94. end GetType
  95.